package com.example.ovulationperiodtracker.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.ovulationperiodtracker.utils.CalendarCustomView;

import java.util.List;

public class MyViewPager extends ViewPager {
    public MyViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        setAdapter(new MyPagerAdapter());

    }


    public static class MyPagerAdapter extends PagerAdapter {

        // 返回页面数量
        @Override
        public int getCount() {
            return 10000;
        }

        // 判断对象是否为当前视图
        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
            return view == object;
        }

        // 初始化页面（创建并添加视图到容器）
        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            //View view = viewList.get(position);

            View view = new CalendarCustomView(container.getContext());

            container.addView(view); // 添加视图到容器
            return view;
        }

        // 销毁页面（从容器中移除视图）
        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            container.removeView((View) object);
        }
    }
}
